﻿using System;
using System.Management;

namespace DCS.CaclulationClient
{
    static class ClientEnvironment
    {
        public static float CpuFrequency
        {
            get
            {
                var frequency = 0.0f;

                var searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_Processor");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    frequency = Convert.ToSingle(queryObj["CurrentClockSpeed"]) / 1000.0f;
                }

                return frequency;
            }
        }

        public static int AvailableRAM
        {
            get
            {
                int memory = 0;

                var searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_OperatingSystem");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    memory = Convert.ToInt32(queryObj["FreePhysicalMemory"]);
                    memory /= 1024;
                }


                return memory;
            }
        }

        public static int AvailableHDDSpace
        {
            get
            {
                UInt64 sumMemory = 0;

                    var searcher =
                        new ManagementObjectSearcher("root\\CIMV2",
                                                     "SELECT * FROM Win32_LogicalDisk");

                    foreach (ManagementObject queryObj in searcher.Get())
                    {
                        sumMemory += Convert.ToUInt64(queryObj["FreeSpace"]);
                    }

                sumMemory /= 1073741824;

                return Convert.ToInt32(sumMemory);
            }
        }
    }
}